

package com.cisdi.info.mh.controller.information;

import com.cisdi.info.mh.dto.information.InformationEditDto;
import com.cisdi.info.mh.entity.information.Information;
import com.cisdi.info.mh.service.information.InformationService;
import com.cisdi.info.simple.dto.base.PageDTO;
import com.cisdi.info.simple.dto.base.PageResultDTO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**module
{
"mh/information/Information": {
"code": "mh/information/Information",
"name1": "资讯",
"url": "/mh/information/Information",
"route": "/mh/information/Information",
"iconClass": "",
"displayIndex": 1,
"parentCode": "mh/information",
"parentName": "资讯管理",
"moduleType": "电脑模块",
"isInUse": "是",
"routeParamsObj": "",
"permissions":
	[
	{
	"code": "mh_information_Information_Add",
	"name1": "新增",
	"fullName": "mh.资讯管理.资讯.新增",
	"moduleCode": "mh/information/Information",
	urls:[
		"/mh/information/Information/createInformation",
		"/mh/information/Information/saveInformation"
	]
	},
	{
	"code": "mh_information_Information_Edit",
	"name1": "编辑",
	"fullName": "mh.资讯管理.资讯.编辑",
	"moduleCode": "mh/information/Information",
	urls:[
		"/mh/information/Information/findInformationForEdit",
		"/mh/information/Information/updateInformation"
	]
	},
	{
	"code": "mh_information_Information_Delete",
	"name1": "删除",
	"fullName": "mh.资讯管理.资讯.删除",
	"moduleCode": "mh/information/Information",
	urls:[
	"/mh/information/Information/deleteInformation"
	]
	},
	{
	"code": "mh_information_Information_View",
	"name1": "查看",
	"fullName": "mh.资讯管理.资讯.查看",
	"moduleCode": "mh/information/Information",
	urls:[
	"/mh/information/Information/findInformations",
	"/mh/information/Information/findInformationForView"
	]
	}
	]
}
}
*/

@RestController
@RequestMapping("/mh/information/Information")
@CrossOrigin(allowCredentials = "true")
public class InformationController {
	private static Logger logger = LogManager.getLogger();



	@Autowired private InformationService informationService;

	@PostMapping("/findInformations")
	public PageResultDTO findInformations(@RequestBody PageDTO pageDTO){
		return this.informationService.findInformations(pageDTO);
	}

	@GetMapping("/findInformation")
	public Information findInformation(@RequestParam Long informationId)
	{
		return this.informationService.findInformation(informationId);
	}

	@GetMapping("/findInformationForView")
	public Information findInformationForView(@RequestParam Long informationId)
	{
		return this.informationService.findInformationWithForeignName(informationId);
	}

	@GetMapping("/findInformationForEdit")
	public InformationEditDto findInformationForEdit(@RequestParam Long informationId)
	{
		InformationEditDto informationEditDto = new InformationEditDto();
		informationEditDto.setInformation(this.informationService.findInformationWithForeignName(informationId));

		this.prepareInformationEditDto(informationEditDto);

		return informationEditDto;
	}

	//创建新的资讯
	@GetMapping("/createInformation")
	public InformationEditDto createInformation()
	{
		InformationEditDto informationEditDto = new InformationEditDto();
		informationEditDto.setInformation(new Information());

		this.prepareInformationEditDto(informationEditDto);
		return informationEditDto;
	}

	private void prepareInformationEditDto(InformationEditDto informationEditDto)
	{
	}

	@PostMapping("/saveInformation")
	public Information saveInformation(@RequestBody Information information)
	{
		return this.informationService.saveInformation(information);
	}

	@PostMapping("/updateInformation")
	public Information updateInformation(@RequestBody Information information)
	{
		return this.informationService.updateInformation(information);
	}

	@GetMapping("/deleteInformation")
	public void deleteInformation(@RequestParam Long informationId)
	{
		this.informationService.deleteInformation(informationId);
	}
	@GetMapping("/findInformationsWithIdNameById")
	public Information findInformationsWithIdNameById(@RequestParam Long informationId)
	{
		return this.informationService.findInformationsWithIdNameById(informationId);
	}

	@GetMapping("/findInformationsWithIdNameByName")
	public List<Information> findInformationsWithIdNameByName(String informationName)
	{
		return this.informationService.findInformationsWithIdNameByName(informationName);
	}
}

